package com.ruoyi.system.service.impl;

import com.ruoyi.system.entity.TargetManage;
import com.ruoyi.system.mapper.TargetManageMapper;
import com.ruoyi.system.service.TargetManageService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 目指标管理(TargetManage)表服务实现类
 *
 * @author makejava
 * @since 2023-03-14 11:12:21
 */
@Service("targetManageService")
public class TargetManageServiceImpl implements TargetManageService {
    @Resource
    private TargetManageMapper targetManageDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TargetManage queryById(Integer id) {
        return this.targetManageDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param targetManage 筛选条件
     * @param pageRequest  分页对象
     * @return 查询结果
     */
    @Override
    public Page<TargetManage> queryByPage(TargetManage targetManage, PageRequest pageRequest) {
        long total = this.targetManageDao.count(targetManage);
        return new PageImpl<>(this.targetManageDao.queryAllByLimit(targetManage, pageRequest), pageRequest, total);
    }

    @Override
    public List<TargetManage> queryAll(TargetManage targetManage) {
        return targetManageDao.queryAll(targetManage);
    }

    /**
     * 新增数据
     *
     * @param targetManage 实例对象
     * @return 实例对象
     */
    @Override
    public TargetManage insert(TargetManage targetManage) {
        this.targetManageDao.insert(targetManage);
        return targetManage;
    }

    /**
     * 修改数据
     *
     * @param targetManage 实例对象
     * @return 实例对象
     */
    @Override
    public TargetManage update(TargetManage targetManage) {
        this.targetManageDao.update(targetManage);
        return this.queryById(targetManage.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.targetManageDao.deleteById(id) > 0;
    }
}
